<?php

namespace App\Http\Controllers;

//use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Cache;

class WechatController extends Controller{
    
    private $appid = 'wx085103a84b05bc31';
    private $secret = '6757949c0a49b23eb08cfe54e47708ce';
    
    public function getCode(){
        
    }
    
    private function getAccessToken(){
//        $redis = new Redis;
        if(Cache::has('access_token')){
            $token = Cache::get('access_token');
        }
        else{
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appid}&secret={$this->secret}";
            $req = file_get_contents($url);
    //        dd($req);
            $data = json_decode($req, TRUE);
            $token = $data['access_token'];
            Cache::put('access_token', $token, 120);
        }
//        dd($token);
        return $token;
    }
}

